define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activtyc/examiation/index',
                    add_url: 'activtyc/examiation/add',
                    edit_url: 'activtyc/examiation/edit',
                    del_url: 'activtyc/examiation/del',
                    multi_url: 'activtyc/examiation/multi',
                    table: 'activity_examination',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'url', title: __('Url'), formatter: Controller.api.formatter.avatar},
                        {field: 'openid', title: __('Openid')},
                        {field: 'name', title: __('Name')},
                        {field: 'phone', title: __('Phone')},
                        {field: 'shen', title: __('Shen'),formatter: Controller.api.formatter.province},
                        {field: 'shi', title: __('Shi'),formatter: Controller.api.formatter.shi},
                        {field: 'xian', title: __('Xian'),formatter: Controller.api.formatter.xian},
                        // {field: 'address', title: __('Address')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('Type')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                avatar: function (value, row, index) {
                    return '<img width="45" height="45" src="'+value+'" class="img-circle">';
                },
                province: function (value, row, index) {
                    var areatext = '';
                    if(value){
                        areatext = Config.arealist[value];
                    }
                    return areatext;
                },
                shi: function (value, row, index) {
                    var areatext = '';
                    if(value){
                        areatext = Config.arealist[value];

                    }
                    return areatext;
                },
                xian: function (value, row, index) {
                    var areatext = '';
                    if(value){
                        areatext = Config.arealist[value];

                    }
                    return areatext;
                },
            }
        }
    };
    return Controller;
});